package com.yinhaochuan.xmlparse;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class FileProcess2 {

	public static void process(String infilename, String outfilename) {
		File infile = new File(infilename);
		File outfile = new File(outfilename);
		try {
			BufferedReader br = new BufferedReader(new FileReader(infile));
			BufferedWriter bw = null;
			String xml = null;
			String str = null;
			bw = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(outfile)));
			xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>";//UTF-8 change to GBK
			bw.write(xml+"\n");
			bw.write("<DOCS>\n");
			while ((str = br.readLine()) != null) {			
					
					bw.write(str);
					bw.write("\n");
			}
			bw.write("</DOCS>\n");
			bw.close();
			br.close();

		}  catch (IOException e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("static-access")
	public static void main(String[] args) throws IOException {
		new FileProcess2().process("data/test.txt", "data/data");
	}

}
